﻿using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CH.FourBoards.LagerWalti.FrontEnd.View.Controls
{
	public class IncludeContainer
	{
		private readonly IList<string> _scripts = new List<string>();
		private readonly IList<string> _styles = new List<string>();

		public void AddScripts(string script)
		{
			if (!_scripts.Contains(script)) {
				_scripts.Add(script);
			}
		}

		public void AddStyle(string style)
		{
			if (!_styles.Contains(style)) {
				_styles.Add(style);
			}
		}

		public void Render(ControlCollection controls)
		{
			foreach (var style in _styles) {
				using (var include = new Literal()) {
					include.Text = string.Format("<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" />", style);
					controls.Add(include);
				}
			}
			foreach (var script in _scripts) {
				using (var include = new Literal()) {
					include.Text = string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", script);
					controls.Add(include);
				}
			}

		}
	}
}